package com.warm.pump.module.sys.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.sys.bean.po.gen.SysUser;
import com.warm.pump.module.sys.mapper.gen.SysUserMapper;
import com.warm.pump.module.sys.bean.po.gen.SysUserExample;
@Repository
public class SysUserDao {
	// 日志对象
	private transient Log log = LogFactory.getLog(this.getClass());
	@Autowired
	private SysUserMapper sysUserMapper;

	// 增加一个后台SysUser表
	
	public boolean insert(SysUser sysUser) {
		try {
			sysUserMapper.insert(sysUser);
			log.debug("后台SysUser表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台SysUser表增加失败");
			throw new ServiceException("后台SysUser表增加失败",e);
		}
	}
	// 增加一个后台SysUser表Selective
	
	public boolean insertSelective(SysUser sysUser) {
		try {
			sysUserMapper.insertSelective(sysUser);
			log.debug("后台SysUser表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台SysUser表增加失败");
			throw new ServiceException("后台SysUser表增加失败",e);
		}
	}

	// 删除一个后台SysUser表
	
	public boolean deleteByPrimaryKey(Long userId) {
		try{
			sysUserMapper.deleteByPrimaryKey(userId);
			log.debug("后台SysUser表删除成功");
			return true;
		} catch(Exception e){
			log.debug("后台SysUser表删除失败");
			throw new ServiceException("后台SysUser表删除失败",e);
		}
	}
	// 删除一个后台SysUser表byMap
	
	public boolean deleteByMap(Map sysUserMap) {
		try{
			sysUserMapper.deleteByExample(createSysUserExample(sysUserMap,null,null));
			log.debug("后台SysUser根据Map删除成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysUser根据GroupID删除失败");
			throw new ServiceException("后台SysUser根据object删除失败",e);
		}
	}
	// 修改一个后台SysUser表
	
	public boolean updateByPrimaryKey(SysUser sysUser) {
		try{
			sysUserMapper.updateByPrimaryKey(sysUser);
			log.debug("后台SysUser表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysUser表修改失败");
			throw new ServiceException("后台SysUser表修改失败",e);
		}
	}
	// 修改一个后台SysUser表Selective
	
	public boolean updateByPrimaryKeySelective(SysUser sysUser) {
		try{
			sysUserMapper.updateByPrimaryKeySelective(sysUser);
			log.debug("后台SysUser表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysUser表修改失败");
			throw new ServiceException("后台SysUser表修改失败",e);
		}
	}
	// 修改一个后台SysUser表
	
	public boolean updateByMap(SysUser sysUser,Map sysUserMap) {
		try{
			sysUserMapper.updateByExample(sysUser,createSysUserExample(sysUserMap,null,null));
			log.debug("后台批量SysUser表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量SysUser表修改失败");
			throw new ServiceException("后台SysUser表批量修改失败",e);
		}
	}
	// 修改一个后台SysUser表Selective
	
	public boolean updateByMapSelective(SysUser sysUser,Map sysUserMap) {
		try{
			sysUserMapper.updateByExampleSelective(sysUser,createSysUserExample(sysUserMap,null,null));
			log.debug("后台批量SysUser表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量SysUser表修改失败");
			throw new ServiceException("后台SysUser表批量修改失败",e);
		}
	}

	// 查询一个后台SysUser表
	
	public SysUser selectByPrimaryKey(Long userId) {
		return sysUserMapper.selectByPrimaryKey(userId);
	}
	
	// 查询一个后台SysUser表-根据map
	
	public SysUser selectByMap(Map sysUserMap) {
		List<SysUser> list = getListByMap(sysUserMap);
		if(list==null||list.isEmpty()){
			return null;
		}else{
			return list.get(0);
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 查询所有后台SysUser表
	
	public List<SysUser> getListByMap(Map sysUserMap) {
		
		return sysUserMapper.selectByExample(createSysUserExample(sysUserMap,null,null));
	}

	//统计后台SysUser表数量
	
	public int countTotalByMap(Map sysUserMap) {
		
		return sysUserMapper.countByExample(createSysUserExample(sysUserMap,null,null));
	}

	
	public List<SysUser> getListByMapPage(Map sysUserMap, int limitStart,
			int limitOffset) {
		
		return sysUserMapper.selectByExample(createSysUserExample(sysUserMap,limitStart,limitOffset));
	}
	
	
	public PageBean getPageBeanByMap(Map sysUserMap,int pageNo,int pageSize) {
		Integer count = countTotalByMap(sysUserMap);
		PageBean pageBean = new PageBean();
		pageBean.setCount(count);
		pageBean.setPageNo(pageNo);
		pageBean.setPageSize(pageSize);
		int limitStart = pageBean.getStartNo();
		int limitOffset = pageSize;
		pageBean.setData(sysUserMapper.selectByExample(createSysUserExample(sysUserMap,limitStart,limitOffset)));
		return pageBean;
	}
		
	private SysUserExample createSysUserExample(Map sysUserMap,Integer limitStart,Integer limitOffset){
			SysUserExample sysUserEx = new SysUserExample();
			SysUserExample.Criteria c = sysUserEx.createCriteria();
				Long userId_null = TypeCast.getLong(sysUserMap.get("userId_null"));
				Long userId_notNull = TypeCast.getLong(sysUserMap.get("userId_notNull"));
				Long userId = TypeCast.getLong(sysUserMap.get("userId"));
				Long userId_not = TypeCast.getLong(sysUserMap.get("userId_not"));
				Long userId_greater = TypeCast.getLong(sysUserMap.get("userId_greater"));
				Long userId_greaterEqual = TypeCast.getLong(sysUserMap.get("userId_greaterEqual"));
				Long userId_less = TypeCast.getLong(sysUserMap.get("userId_less"));
				Long userId_lessEqual = TypeCast.getLong(sysUserMap.get("userId_lessEqual"));
				List<Long> userId_in = TypeCast.getLongList(sysUserMap.get("userId_in"));
				List<Long> userId_notIn = TypeCast.getLongList(sysUserMap.get("userId_notIn"));
				Long userId_between1 = TypeCast.getLong(sysUserMap.get("userId_between1"));
				Long userId_between2 = TypeCast.getLong(sysUserMap.get("userId_between2"));
				Long userId_notBetween1 = TypeCast.getLong(sysUserMap.get("userId_notBetween1"));
				Long userId_notBetween2 = TypeCast.getLong(sysUserMap.get("userId_notBetween2"));
				
				if(userId_null != null){
					c.andUserIdIsNull();
				}
				if(userId_notNull != null){
					c.andUserIdIsNotNull();
				}
				if(userId != null){
					c.andUserIdEqualTo(userId);
				}
				if(userId_not != null){
					c.andUserIdNotEqualTo(userId_not);
				}
				if(userId_greater != null){
					c.andUserIdGreaterThan(userId_greater);
				}
				if(userId_greaterEqual != null){
					c.andUserIdGreaterThanOrEqualTo(userId_greaterEqual);
				}
				if(userId_less != null){
					c.andUserIdLessThan(userId_less);
				}
				if(userId_lessEqual != null){
					c.andUserIdLessThanOrEqualTo(userId_lessEqual);
				}
				if(userId_in != null){
					c.andUserIdIn(userId_in);
				}
				if(userId_notIn != null){
					c.andUserIdNotIn(userId_notIn);
				}
				if(userId_between1 != null){
					c.andUserIdBetween(userId_between1,userId_between2);
				}
				if(userId_notBetween1 != null){
					c.andUserIdNotBetween(userId_notBetween1,userId_notBetween2);
				}
				String username_null = TypeCast.getString(sysUserMap.get("username_null"));
				String username_notNull = TypeCast.getString(sysUserMap.get("username_notNull"));
				String username = TypeCast.getString(sysUserMap.get("username"));
				String username_not = TypeCast.getString(sysUserMap.get("username_not"));
				String username_greater = TypeCast.getString(sysUserMap.get("username_greater"));
				String username_greaterEqual = TypeCast.getString(sysUserMap.get("username_greaterEqual"));
				String username_less = TypeCast.getString(sysUserMap.get("username_less"));
				String username_lessEqual = TypeCast.getString(sysUserMap.get("username_lessEqual"));
				String username_like = TypeCast.getString(sysUserMap.get("username_like"));
				String username_notLike = TypeCast.getString(sysUserMap.get("username_notLike"));
				List<String> username_in = TypeCast.getStringList(sysUserMap.get("username_in"));
				List<String> username_notIn = TypeCast.getStringList(sysUserMap.get("username_notIn"));
				String username_between1 = TypeCast.getString(sysUserMap.get("username_between1"));
				String username_between2 = TypeCast.getString(sysUserMap.get("username_between2"));
				String username_notBetween1 = TypeCast.getString(sysUserMap.get("username_notBetween1"));
				String username_notBetween2 = TypeCast.getString(sysUserMap.get("username_notBetween2"));
				
				if(username_null != null){
					c.andUsernameIsNull();
				}
				if(username_notNull != null){
					c.andUsernameIsNotNull();
				}
				if(username != null){
					c.andUsernameEqualTo(username);
				}
				if(username_not != null){
					c.andUsernameNotEqualTo(username_not);
				}
				if(username_greater != null){
					c.andUsernameGreaterThan(username_greater);
				}
				if(username_greaterEqual != null){
					c.andUsernameGreaterThanOrEqualTo(username_greaterEqual);
				}
				if(username_less != null){
					c.andUsernameLessThan(username_less);
				}
				if(username_lessEqual != null){
					c.andUsernameLessThanOrEqualTo(username_lessEqual);
				}
				if(username_like != null){
					c.andUsernameLike(username_like);
				}
				if(username_notLike != null){
					c.andUsernameNotLike(username_notLike);
				}
				if(username_in != null){
					c.andUsernameIn(username_in);
				}
				if(username_notIn != null){
					c.andUsernameNotIn(username_notIn);
				}
				if(username_between1 != null){
					c.andUsernameBetween(username_between1,username_between2);
				}
				if(username_notBetween1 != null){
					c.andUsernameNotBetween(username_notBetween1,username_notBetween2);
				}
				String password_null = TypeCast.getString(sysUserMap.get("password_null"));
				String password_notNull = TypeCast.getString(sysUserMap.get("password_notNull"));
				String password = TypeCast.getString(sysUserMap.get("password"));
				String password_not = TypeCast.getString(sysUserMap.get("password_not"));
				String password_greater = TypeCast.getString(sysUserMap.get("password_greater"));
				String password_greaterEqual = TypeCast.getString(sysUserMap.get("password_greaterEqual"));
				String password_less = TypeCast.getString(sysUserMap.get("password_less"));
				String password_lessEqual = TypeCast.getString(sysUserMap.get("password_lessEqual"));
				String password_like = TypeCast.getString(sysUserMap.get("password_like"));
				String password_notLike = TypeCast.getString(sysUserMap.get("password_notLike"));
				List<String> password_in = TypeCast.getStringList(sysUserMap.get("password_in"));
				List<String> password_notIn = TypeCast.getStringList(sysUserMap.get("password_notIn"));
				String password_between1 = TypeCast.getString(sysUserMap.get("password_between1"));
				String password_between2 = TypeCast.getString(sysUserMap.get("password_between2"));
				String password_notBetween1 = TypeCast.getString(sysUserMap.get("password_notBetween1"));
				String password_notBetween2 = TypeCast.getString(sysUserMap.get("password_notBetween2"));
				
				if(password_null != null){
					c.andPasswordIsNull();
				}
				if(password_notNull != null){
					c.andPasswordIsNotNull();
				}
				if(password != null){
					c.andPasswordEqualTo(password);
				}
				if(password_not != null){
					c.andPasswordNotEqualTo(password_not);
				}
				if(password_greater != null){
					c.andPasswordGreaterThan(password_greater);
				}
				if(password_greaterEqual != null){
					c.andPasswordGreaterThanOrEqualTo(password_greaterEqual);
				}
				if(password_less != null){
					c.andPasswordLessThan(password_less);
				}
				if(password_lessEqual != null){
					c.andPasswordLessThanOrEqualTo(password_lessEqual);
				}
				if(password_like != null){
					c.andPasswordLike(password_like);
				}
				if(password_notLike != null){
					c.andPasswordNotLike(password_notLike);
				}
				if(password_in != null){
					c.andPasswordIn(password_in);
				}
				if(password_notIn != null){
					c.andPasswordNotIn(password_notIn);
				}
				if(password_between1 != null){
					c.andPasswordBetween(password_between1,password_between2);
				}
				if(password_notBetween1 != null){
					c.andPasswordNotBetween(password_notBetween1,password_notBetween2);
				}
				String email_null = TypeCast.getString(sysUserMap.get("email_null"));
				String email_notNull = TypeCast.getString(sysUserMap.get("email_notNull"));
				String email = TypeCast.getString(sysUserMap.get("email"));
				String email_not = TypeCast.getString(sysUserMap.get("email_not"));
				String email_greater = TypeCast.getString(sysUserMap.get("email_greater"));
				String email_greaterEqual = TypeCast.getString(sysUserMap.get("email_greaterEqual"));
				String email_less = TypeCast.getString(sysUserMap.get("email_less"));
				String email_lessEqual = TypeCast.getString(sysUserMap.get("email_lessEqual"));
				String email_like = TypeCast.getString(sysUserMap.get("email_like"));
				String email_notLike = TypeCast.getString(sysUserMap.get("email_notLike"));
				List<String> email_in = TypeCast.getStringList(sysUserMap.get("email_in"));
				List<String> email_notIn = TypeCast.getStringList(sysUserMap.get("email_notIn"));
				String email_between1 = TypeCast.getString(sysUserMap.get("email_between1"));
				String email_between2 = TypeCast.getString(sysUserMap.get("email_between2"));
				String email_notBetween1 = TypeCast.getString(sysUserMap.get("email_notBetween1"));
				String email_notBetween2 = TypeCast.getString(sysUserMap.get("email_notBetween2"));
				
				if(email_null != null){
					c.andEmailIsNull();
				}
				if(email_notNull != null){
					c.andEmailIsNotNull();
				}
				if(email != null){
					c.andEmailEqualTo(email);
				}
				if(email_not != null){
					c.andEmailNotEqualTo(email_not);
				}
				if(email_greater != null){
					c.andEmailGreaterThan(email_greater);
				}
				if(email_greaterEqual != null){
					c.andEmailGreaterThanOrEqualTo(email_greaterEqual);
				}
				if(email_less != null){
					c.andEmailLessThan(email_less);
				}
				if(email_lessEqual != null){
					c.andEmailLessThanOrEqualTo(email_lessEqual);
				}
				if(email_like != null){
					c.andEmailLike(email_like);
				}
				if(email_notLike != null){
					c.andEmailNotLike(email_notLike);
				}
				if(email_in != null){
					c.andEmailIn(email_in);
				}
				if(email_notIn != null){
					c.andEmailNotIn(email_notIn);
				}
				if(email_between1 != null){
					c.andEmailBetween(email_between1,email_between2);
				}
				if(email_notBetween1 != null){
					c.andEmailNotBetween(email_notBetween1,email_notBetween2);
				}
				String mobile_null = TypeCast.getString(sysUserMap.get("mobile_null"));
				String mobile_notNull = TypeCast.getString(sysUserMap.get("mobile_notNull"));
				String mobile = TypeCast.getString(sysUserMap.get("mobile"));
				String mobile_not = TypeCast.getString(sysUserMap.get("mobile_not"));
				String mobile_greater = TypeCast.getString(sysUserMap.get("mobile_greater"));
				String mobile_greaterEqual = TypeCast.getString(sysUserMap.get("mobile_greaterEqual"));
				String mobile_less = TypeCast.getString(sysUserMap.get("mobile_less"));
				String mobile_lessEqual = TypeCast.getString(sysUserMap.get("mobile_lessEqual"));
				String mobile_like = TypeCast.getString(sysUserMap.get("mobile_like"));
				String mobile_notLike = TypeCast.getString(sysUserMap.get("mobile_notLike"));
				List<String> mobile_in = TypeCast.getStringList(sysUserMap.get("mobile_in"));
				List<String> mobile_notIn = TypeCast.getStringList(sysUserMap.get("mobile_notIn"));
				String mobile_between1 = TypeCast.getString(sysUserMap.get("mobile_between1"));
				String mobile_between2 = TypeCast.getString(sysUserMap.get("mobile_between2"));
				String mobile_notBetween1 = TypeCast.getString(sysUserMap.get("mobile_notBetween1"));
				String mobile_notBetween2 = TypeCast.getString(sysUserMap.get("mobile_notBetween2"));
				
				if(mobile_null != null){
					c.andMobileIsNull();
				}
				if(mobile_notNull != null){
					c.andMobileIsNotNull();
				}
				if(mobile != null){
					c.andMobileEqualTo(mobile);
				}
				if(mobile_not != null){
					c.andMobileNotEqualTo(mobile_not);
				}
				if(mobile_greater != null){
					c.andMobileGreaterThan(mobile_greater);
				}
				if(mobile_greaterEqual != null){
					c.andMobileGreaterThanOrEqualTo(mobile_greaterEqual);
				}
				if(mobile_less != null){
					c.andMobileLessThan(mobile_less);
				}
				if(mobile_lessEqual != null){
					c.andMobileLessThanOrEqualTo(mobile_lessEqual);
				}
				if(mobile_like != null){
					c.andMobileLike(mobile_like);
				}
				if(mobile_notLike != null){
					c.andMobileNotLike(mobile_notLike);
				}
				if(mobile_in != null){
					c.andMobileIn(mobile_in);
				}
				if(mobile_notIn != null){
					c.andMobileNotIn(mobile_notIn);
				}
				if(mobile_between1 != null){
					c.andMobileBetween(mobile_between1,mobile_between2);
				}
				if(mobile_notBetween1 != null){
					c.andMobileNotBetween(mobile_notBetween1,mobile_notBetween2);
				}
				Integer status_null = TypeCast.getInteger(sysUserMap.get("status_null"));
				Integer status_notNull = TypeCast.getInteger(sysUserMap.get("status_notNull"));
				Integer status = TypeCast.getInteger(sysUserMap.get("status"));
				Integer status_not = TypeCast.getInteger(sysUserMap.get("status_not"));
				Integer status_greater = TypeCast.getInteger(sysUserMap.get("status_greater"));
				Integer status_greaterEqual = TypeCast.getInteger(sysUserMap.get("status_greaterEqual"));
				Integer status_less = TypeCast.getInteger(sysUserMap.get("status_less"));
				Integer status_lessEqual = TypeCast.getInteger(sysUserMap.get("status_lessEqual"));
				List<Integer> status_in = TypeCast.getIntegerList(sysUserMap.get("status_in"));
				List<Integer> status_notIn = TypeCast.getIntegerList(sysUserMap.get("status_notIn"));
				Integer status_between1 = TypeCast.getInteger(sysUserMap.get("status_between1"));
				Integer status_between2 = TypeCast.getInteger(sysUserMap.get("status_between2"));
				Integer status_notBetween1 = TypeCast.getInteger(sysUserMap.get("status_notBetween1"));
				Integer status_notBetween2 = TypeCast.getInteger(sysUserMap.get("status_notBetween2"));
				
				if(status_null != null){
					c.andStatusIsNull();
				}
				if(status_notNull != null){
					c.andStatusIsNotNull();
				}
				if(status != null){
					c.andStatusEqualTo(status);
				}
				if(status_not != null){
					c.andStatusNotEqualTo(status_not);
				}
				if(status_greater != null){
					c.andStatusGreaterThan(status_greater);
				}
				if(status_greaterEqual != null){
					c.andStatusGreaterThanOrEqualTo(status_greaterEqual);
				}
				if(status_less != null){
					c.andStatusLessThan(status_less);
				}
				if(status_lessEqual != null){
					c.andStatusLessThanOrEqualTo(status_lessEqual);
				}
				if(status_in != null){
					c.andStatusIn(status_in);
				}
				if(status_notIn != null){
					c.andStatusNotIn(status_notIn);
				}
				if(status_between1 != null){
					c.andStatusBetween(status_between1,status_between2);
				}
				if(status_notBetween1 != null){
					c.andStatusNotBetween(status_notBetween1,status_notBetween2);
				}
				Date createTime_null = TypeCast.getDate(sysUserMap.get("createTime_null"));
				Date createTime_notNull = TypeCast.getDate(sysUserMap.get("createTime_notNull"));
				Date createTime = TypeCast.getDate(sysUserMap.get("createTime"));
				Date createTime_not = TypeCast.getDate(sysUserMap.get("createTime_not"));
				Date createTime_greater = TypeCast.getDate(sysUserMap.get("createTime_greater"));
				Date createTime_greaterEqual = TypeCast.getDate(sysUserMap.get("createTime_greaterEqual"));
				Date createTime_less = TypeCast.getDate(sysUserMap.get("createTime_less"));
				Date createTime_lessEqual = TypeCast.getDate(sysUserMap.get("createTime_lessEqual"));
				List<Date> createTime_in = TypeCast.getDateList(sysUserMap.get("createTime_in"));
				List<Date> createTime_notIn = TypeCast.getDateList(sysUserMap.get("createTime_notIn"));
				Date createTime_between1 = TypeCast.getDate(sysUserMap.get("createTime_between1"));
				Date createTime_between2 = TypeCast.getDate(sysUserMap.get("createTime_between2"));
				Date createTime_notBetween1 = TypeCast.getDate(sysUserMap.get("createTime_notBetween1"));
				Date createTime_notBetween2 = TypeCast.getDate(sysUserMap.get("createTime_notBetween2"));
				
				if(createTime_null != null){
					c.andCreateTimeIsNull();
				}
				if(createTime_notNull != null){
					c.andCreateTimeIsNotNull();
				}
				if(createTime != null){
					c.andCreateTimeEqualTo(createTime);
				}
				if(createTime_not != null){
					c.andCreateTimeNotEqualTo(createTime_not);
				}
				if(createTime_greater != null){
					c.andCreateTimeGreaterThan(createTime_greater);
				}
				if(createTime_greaterEqual != null){
					c.andCreateTimeGreaterThanOrEqualTo(createTime_greaterEqual);
				}
				if(createTime_less != null){
					c.andCreateTimeLessThan(createTime_less);
				}
				if(createTime_lessEqual != null){
					c.andCreateTimeLessThanOrEqualTo(createTime_lessEqual);
				}
				if(createTime_in != null){
					c.andCreateTimeIn(createTime_in);
				}
				if(createTime_notIn != null){
					c.andCreateTimeNotIn(createTime_notIn);
				}
				if(createTime_between1 != null){
					c.andCreateTimeBetween(createTime_between1,createTime_between2);
				}
				if(createTime_notBetween1 != null){
					c.andCreateTimeNotBetween(createTime_notBetween1,createTime_notBetween2);
				}
			if(sysUserMap.get("orderBy")!=null){
				sysUserEx.setOrderByClause((String)sysUserMap.get("orderBy"));
			}
			if(limitStart != null && limitOffset != null){
				sysUserEx.setLimitStart(limitStart);
				sysUserEx.setLimitOffset(limitOffset);
			}
			
			return sysUserEx;
	}
}
